home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d18 / turbotut.arc / AREAS.PAS < prev    next >
Pascal/Delphi Source File  |  1989-06-30  |  2KB  |  72 lines

  1. PROGRAM calculate_areas;
  2.  
  3. (*  This program is dedicated to Marsha, a student, who
  4.     was of tremendous help during the debugging stage of
  5.     the text and programs. Thanks Marsha!
  6. *)
  7.  
  8. VAR in_char : CHAR;
  9.  
  10. PROCEDURE area_of_square;
  11. VAR length,area : REAL;
  12. BEGIN
  13.   WRITE('Square   Enter length of side ');
  14.   READLN(length);
  15.   area := length * length;
  16.   WRITELN('The area is ',area:12:4);
  17. END;
  18.  
  19. PROCEDURE area_of_rectangle;
  20. VAR width,height,area : REAL;
  21. BEGIN
  22.   WRITE('Rectangle   Enter width ');
  23.   READLN(width);
  24.   WRITE('Enter height ');
  25.   READ(height);
  26.   area := width * height;
  27.   WRITELN('    The area is ',area:12:4);
  28. END;
  29.  
  30. PROCEDURE area_of_triangle;
  31. VAR base,height,area : REAL;
  32. BEGIN
  33.   WRITE('Triangle     Enter base ');
  34.   READLN(base);
  35.   WRITE('Enter height ');
  36.   READ(height);
  37.   area := 0.5 * base * height;
  38.   WRITELN('    The area is ',area:12:3);
  39. END;
  40.  
  41. PROCEDURE area_of_circle;
  42. VAR radius,area : REAL;
  43. BEGIN
  44.   WRITE('Circle    Enter radius ');
  45.   READLN(radius);
  46.   area := 3.141592 * radius * radius;
  47.   WRITELN('The area is ',area:12:3);
  48. END;
  49.  
  50. BEGIN  (* main program *)
  51. REPEAT
  52.   WRITELN;
  53.   WRITELN('You only need to input the first letter of the selection');
  54.   WRITELN('Select shape; Square Rectangle Triangle Circle Quit');
  55.   WRITE('Requested shape is ');
  56.   REPEAT UNTIL keypressed;
  57.   READ(kbd,in_char);
  58.   CASE in_char OF
  59.   'S' : area_of_square;
  60.   's' : area_of_square;
  61.   'R' : area_of_rectangle;
  62.   'r' : area_of_rectangle;
  63.   'T' : area_of_triangle;
  64.   't' : area_of_triangle;
  65.   'C' : area_of_circle;
  66.   'c' : area_of_circle;
  67.   'Q' : WRITELN('Quit');
  68.   'q' : WRITELN('Quit');
  69.   ELSE WRITELN(' undefined entry');
  70.   END;
  71. UNTIL (in_char = 'Q') OR (in_char = 'q');
  72. END.  (* of main program *)